﻿
Imports std
Imports xmlctrl
Imports webctrl
Imports wfileis.data

Public Class catpvp
    Inherits previewPage

    Public Const _pathidentity As String = network.pathSeperator + "c"

    <ThreadStatic()> Private Shared _title As String = Nothing
    <ThreadStatic()> Private Shared _category As String = Nothing

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    Protected Overrides Function title() As String
        Return _title
    End Function

    Protected Overrides Function topics(ByVal start As Int64, ByVal count As Int64) As list(Of String)
        Dim cat As category = Nothing
        cat = New category()
        If cat.read(_category) AndAlso cat.size() > 0 Then
            Dim it As category.iterator = Nothing
            it = cat.begin()
            Dim i As Int64
            For i = 0 To start - 1
                it += 1
                If it = cat.end() Then
                    Exit For
                End If
            Next
            If i < start Then
                Return Nothing
            Else
                Dim rtn As list(Of String) = Nothing
                rtn = New list(Of String)()
                For i = 0 To count - 1
                    If isemptystring(+it) Then
                        i -= 1
                    Else
                        rtn.push_back(+it)
                    End If
                    it += 1
                    If it = cat.end() Then
                        Exit For
                    End If
                Next
                Return rtn
            End If
        Else
            Return Nothing
        End If
    End Function

    Protected Overrides Sub prepare(ByVal context As httpContext)
        MyBase.prepare(context)
        _category = urlUtils.urldecode(strmid(context.url().path(), strlen(pathidentity())))
        _title = context.string(stringId.CATEGORY_VIEW_TITLE) + _category
    End Sub
End Class
